//---------------------------------------------------------------------------------------------
// Volume Control Scripts
// 
//---------------------------------------------------------------------------------------------
void $SCE Volume Up$ () 												// Increase volume by 1
{
 	int Volume;
		
	CustomListData MasterAudio;											//Create a data object for the masterUadio List data
	ListManagerGetItem(ListDataType.MasterAudioType, 0, MasterAudio);   //read the first row of data from the list
	Volume = MasterAudio.ReadInt32(8);									//extract the Volume which starts at Byte 8 and is a 32bit int (See MasterAudioType List)
	if(Volume <100)														//If volume is les than 100 inc the volume by one using an action then also store this value
		{																//out to our system variable to be used by other functions.
		Volume +=1;
		SendAction(ApplicationIDs.MediaApp, ActionIDs.MediaApp_MasterVolumeUp, 1);//This action will update the List with the new value and send it to the app.
		smWrite(VariableIDs._Volume, Volume);							//update the variable used by the config
		}



}

//---------------------------------------------------------------------------------------------
// Murphy Scripting
// - Leave EventName as $SCE Volume Down$ for main script method
//---------------------------------------------------------------------------------------------
void $SCE Volume Down$ () 												//Decrease Volume by 1
{
int Volume;
		
	CustomListData MasterAudio;											//Create a data object for the masterUadio List data%
	ListManagerGetItem(ListDataType.MasterAudioType, 0, MasterAudio);   //read the first row of data from the list
	Volume = MasterAudio.ReadInt32(8);									//extract the Volume which starts at Byte 8 and is a 32bit int (See MasterAudioType List)
	if(Volume >0)														//If volume greater than 0 dec the volume by one using an action then also store this value
		{																//out to our system variable to be used by other functions.
		Volume -=1;
		SendAction(ApplicationIDs.MediaApp, ActionIDs.MediaApp_MasterVolumeDown, 1);
		smWrite(VariableIDs._Volume, Volume);
		}    
}

//---------------------------------------------------------------------------------------------
// Murphy Scripting
// - Leave EventName as $SCE Read Current Volume from List$ for main script method
//---------------------------------------------------------------------------------------------
void $SCE Read Current Volume from List$ () 									// function not used - reads volume from list and pts it in a config variable
{
	int Volume;
	CustomListData MasterAudio;											
	ListManagerGetItem(ListDataType.MasterAudioType, 0, MasterAudio);   
	Volume = MasterAudio.ReadInt32(8);											//extract the Volume which starts at Byte 8 and is a 32bit int (See MasterAudioType List)
	smWrite(VariableIDs._Volume, Volume);										// store this value out to our system variable to be used by other functions.
	
}

//---------------------------------------------------------------------------------------------
// Murphy Scripting
// - Leave EventName as $SCE Initialize Volume$ for main script method
//---------------------------------------------------------------------------------------------
void $SCE Initialize Volume$ () 												//Sets the volume level to 20 as a starting point - must be called by a delayed action
																				//a two second delay after power up is needed before calling this function
{
	int Volume = 20;
	CustomListData MasterAudio;
 	MasterAudio.WriteInt32(8, (Volume - 1));									//Set the volume in the list object to desired level minus one, starts in the eighth byte.
	ListManagerSetItem(ListDataType.MasterAudioType, 0, MasterAudio);			//Load the list with the volume level,  
	SendAction(ApplicationIDs.MediaApp, ActionIDs.MediaApp_MasterVolumeUp, 1);	// Call the action to add one to the list volume and transfer it to the audio app.
  	smWrite(VariableIDs._Volume, Volume);										// store this value out to our system variable to be used by other functions.
	sendEvent(EventIDs._UE_Animate_Volume_Slider_Position);						// Set the volume slider position to the initialized value
    
}

//---------------------------------------------------------------------------------------------
// Murphy Scripting
// - Leave EventName as $SCE Set Volume From Slider Position$ for main script method
//---------------------------------------------------------------------------------------------
void $SCE Set Volume From Slider Position$ () 									//sets volume based on touch position and handles animating the slider position
{
  	int Volume;
	int TouchCurrentX;
	
	smRead(VariableIDs.Touch_Current_X, TouchCurrentX);

	Volume = (TouchCurrentX - 750)/4;											// the offset of 750 is the center position of the slider at 0% volume
	if (Volume > 100) 															// if the container is moved this offset will need to be updated
		{
		Volume = 100;															// limit the volume min/max to 0% and 100% since the touch position can move
		}																		// out of bounds
	if (Volume <0) 																
		{
		Volume = 0;
		}
	smWrite(VariableIDs._Volume, Volume);								
	
	CustomListData MasterAudio;													//Create a data object for the master audio list
	
 	MasterAudio.WriteInt32(8, Volume);											//Set the volume in the data object to desired level, starts in the eighth byte.
	ListManagerSetItem(ListDataType.MasterAudioType, 0, MasterAudio);			//Load the list with the data object containing the volume level,  
	sendEvent(EventIDs._UE_Animate_Volume_Slider_Position);						// Set the volume slider position based on the variable _Volume

}